package ye;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.Random;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class httpTest {

    static Logger logger = Logger.getLogger("httpTest");

    public static void main(String[] args) {


        String aaa="last_trade_no_4200000114201806044294259308";




        logger.info("start request");
        JSONObject obj11 = JSONObject.fromObject( "{\"url\":[\"http://172.18.20.158/qrmgr/index.php/Api\",\"http://172.18.20.158/qrmgr/index.php/Api\"]}");

        String urls = "url1111,url2222";
        long startTime1 = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            String[] ayy = urls.split(",");
            int index = ayy.length;
        }
        long endTime1 = System.currentTimeMillis();
        float excTime1 = (float) (endTime1 - startTime1);
        System.out.println("split 执行时间：" + excTime1 + "ms");

//        Random random = new Random();
//
//        System.out.println("ayy.length:" + ayy.length);
//        for (int i = 0; i < 10; i++) {
//            int index = random.nextInt(ayy.length);
//            System.out.println("index:" + index);
//        }


        String jsonStr = "{\"url\":[\"http://172.18.20.158/qrmgr/index.php/Api\",\"http://172.18.20.158/qrmgr/index.php/Api\"]}";

        long startTime2 = System.currentTimeMillis();
        for (int i = 0; i < 100; i++) {
            JSONObject obj = JSONObject.fromObject(jsonStr);
            JSONArray arr = obj.getJSONArray("url");

            int index = arr.size();
        }
        long endTime2 = System.currentTimeMillis();
        float excTime2 = (float) (endTime2 - startTime2);
        System.out.println("JSONObject 执行时间：" + excTime2 + "ms");



//        String[] urls = new String[]{"http://www.cqcp.net"
//                , "http://www.tjflcpw.com/report/ssc_jiben_report.aspx?term_num=10"
//                , "https://www.cp9345.com/getLotteryBase.do?gameCode=bjpk10"};
//
//        while (true) {
//            for (String url : urls) {
//                try {
//                    String result = HttpClientHelper.doGet(url);
//                    logger.info(url + ",result :" + result);
//
//                } catch (Exception ex) {
//
//                    logger.info(url + ",result :" + ex.getMessage());
//                }
//            }
//            try {
//                Thread.sleep(60 * 1000);
//            } catch (Exception ex) {
//
//                logger.info("Thread.sleep Exception:" + ex.getMessage());
//            }
//        }


//        ObjectService service = new ObjectService();
//        ThreadA a = new ThreadA(service);
//        a.setName("a");
//        a.start();
//        ThreadB b = new ThreadB(service);
//        b.setName("b");
//        b.start();

//        String text = "asdftd003ioihf003sdf";
//        String pattern = "td\\d{3,10}|hf\\d{3,10}";
//        System.out.println("text.matches(pattern):" + text.matches(pattern));
//        Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
//        Matcher m = p.matcher(text);
//        StringBuffer sb = new StringBuffer();
//        while (m.find()) {
//            //m.appendReplacement(sb, "dog");
//            sb.append(m.group() + ",");
//        }
//        //m.appendTail(sb);
//        System.out.println(sb.toString());


        //System.out.println("asdjfTDsdfh".indexOf("TD"));


        // System.out.println("Hello World!");
    }


    public static void caiPiaoTest() {
        String[] urls = new String[]{"http://www.cqcp.net"
                , "http://www.tjflcpw.com/report/ssc_jiben_report.aspx?term_num=10"
                , "https://www.cp9345.com/getLotteryBase.do?gameCode=bjpk10"};

        while (true) {
            for (String url : urls) {
                try {
                    String result = HttpClientHelper.doGet(url);
                    logger.info(url + ",result :" + result);

                } catch (Exception ex) {

                    logger.info(url + ",result :" + ex.getMessage());
                }
            }
            try {
                Thread.sleep(60 * 1000);
            } catch (Exception ex) {

                logger.info("Thread.sleep Exception:" + ex.getMessage());
            }
        }


    }

}
